Trading





Kerry Back

Workflow

  • Positions spreadsheet (initially all zero)
  • Ranks spreadsheet (from train and predict)
  • Prices spreadsheet (most recent stock prices)
  • (Positions + Ranks + Prices) \(\rightarrow\) Trades spreadsheet
  • (Positions + Trades) \(\rightarrow\) updated Positions

Initial long portfolio

  • Cash to invest
  • Select numstocks, equal weight (for example)
  • (cash/numstocks) = $ per stock
  • Ranks \(\rightarrow\) top numstocks
  • Prices \(\rightarrow\) shares = $ per stock / price
  • \(\Rightarrow\) Trades \(\Rightarrow\) Positions

Trading

  • Update cash = cash + interest
  • New Ranks (no longer holding just top stocks)
  • New Prices (no longer equally weighted)
  • Need to decide how (Positions + Ranks + Prices) \(\rightarrow\) Trades

Example

  • If new rank is below some threshold, sell all shares
  • Otherwise, if new weight is above some threshold, sell some shares
  • Invest updated cash + proceeds from sales as
    • Calculate how many to buy, dividing cash equally, and not exceeding target weight
    • Allocate funds among top stocks not currently owned

Example

  • 26 stocks in universe, want to hold 5, target weight = 20%
  • $100,000 initial investment
ranks = pd.read_excel("files/ranks0.xlsx", index_col=0)
prices = pd.read_excel("files/prices0.xlsx", index_col=0)